package cn.whr.server1.repository;

import cn.whr.server1.entity.CodeEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

@Transactional
public interface CodeRepository extends JpaRepository<CodeEntity, String> {

    @Modifying
    @Query(value = "update bs_t_user set pass_word=?1, status=?3 where pid=?2", nativeQuery = true)
    Integer updatePwdByPid(String pwd, String pid, String status);

    @Modifying
    @Query(value = "delete  from bs_t_code where name = ?1", nativeQuery = true)
    Integer deleteByName(String name);

    @Query(value = "select * from bs_t_code c where c.name=?1 and c.phone=?2 order by c.failure_time desc limit 1", nativeQuery = true)
    CodeEntity findByNameAndPhone(String name, String phone);

}
